<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Award_2013 extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/home
	 *	- or -  
	 * 		http://example.com/index.php/home/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
    function __construct()
    {
        parent::__construct(); 
		
		//Google Analytics ID
		$this->data['ga_id'] = 17;
				
		//Set Cache
		//$this->output->cache(2);
		//Load Database
		$this->DB_AWARD = $this->load->database("you2play_award_2013",TRUE);
		//Load Library
		$this->load->library('user_agent');
		//Load model
		$this->load->model('award_model');
		//Set Templates
		$this->folder_templates = "award/2013/";
      	//Set Script Default
   		$this->data['js']    = array('jquery-1.8.2.min.js','award2013Script.js');
    	//Set Style Default
    	$this->data['css']   = array(''.(!ONIDEV ? 'award2013Style.min.css':'award2013Style.css').'');	
        //Set Script External Default	
        $this->data['external_js']  = '';
        //Set style External Default	
        $this->data['external_css'] = '';
		//Set Base url
		$this->data['award_url']  = "http://award.you2play.com/archives/2013/";	
		//Set Asset Path		
		$this->data['asset_award_upload_path']  = "../uploads/award/2013/";
		//Set Asset Image Path		
		$this->data['asset_award_image_path']  = "award/2013/";					
		//Set Upload Folder
		$this->upload_folder = (!ONIDEV ? $this->config->item('path_asset_url').'assets/uploads/':realpath('assets/uploads/').'/');
		$this->expireShowPercent = strtotime('2013-02-19 00:00:00');
		$this->expireMent = strtotime('2013-02-20 00:00:00');
		$this->expireActivity = strtotime('2013-02-20 15:00:00');
		$this->showWinner = strtotime('2013-02-21 23:00:00');
						
		//Load Library
		//$this->load->library('pagination');	
    }
	
	/*FaceBook*/
	public function get_user_fb()
	{
		$user_id = $this->input->post('user_id');
		$user_name = $this->input->post('user_name');
		$data = array(
			'fb_id' => $user_id,
			'fb_name' => $user_name
		);
		$this->session->set_userdata($data);		
	}
	
	public function delete_user_fb()
	{
		$data = array('fb_id' => '', 'fb_name' => '');
		$this->session->unset_userdata($data);
	}
	
	/*Close Popup*/
	public function close_popup()
	{
		echo "<script>close();</script>";
		exit;
	}
	
	/*Sponser*/
	function module_sponser2()
	{
		$this->load->view("award/module_sponser2");		
	}
	
	/*Home*/	 
	public function index()
	{
		//Load Nova Slider
		$this->data['js'][] = "jquery.nivo.slider.pack.js";
		$this->data['css'][] = "nivo-slider.css";
		$this->data['css'][] = "themes/default/default.css";

		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;
	
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/index";
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}
	
	/*Show*/
	public function show()
	{
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	/*Vote*/
	public function vote()
	{
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;
	
		$time_limit = time()-(60*60); //last 1 hours 
		//$this->data['dataVote'] = json_decode(file_get_contents($this->upload_folder.''."/award/vote/vote.json"));
		$this->data['dataVote'] = $this->DB_AWARD->get('award_vote_score',1)->row();
		$dataResult = $this->DB_AWARD->select('cat,at')->get_where('award_vote',"user_id = '".$this->session->userdata('fb_id')."' AND unix_timestamp(fb_time) > '".$time_limit."'")->result();
		foreach($dataResult as $value):
			$this->data['cat'.$value->cat] = $value->at;
		endforeach;
		
		for($i=1;$i<=10;$i++):
			for($j=1;$j<=6;$j++):
				$this->data['dataXML'.sprintf('%02d',$i).$j] = simplexml_load_file($this->upload_folder.$this->data['asset_award_upload_path']."artist/".sprintf('%02d',$i)."/".$j."/data.xml");
			endfor;
		endfor;
		$this->data['dataCategory'] = array(
			'01' => 'ศิลปินชายยอดนิยม / Favorite Male Artist',
			'02' => 'ศิลปินหญิงยอดนิยม / Favorite Female Artist',
			'03' => 'ศิลปินหน้าใหม่ยอดนิยม / Favorite New Artist',
			'04' => 'ศิลปิน Teen Pop ยอดนิยม / Favorite Teen Pop Artist',
			'05' => 'ศิลปินคู่หรือกลุ่มยอดนิยม / Favorite Duo / Group Artist',
			'06' => 'มิวสิควีดีโอเพลงไทยยอดนิยม / Favorite Thai Music Video',
			'07' => 'ศิลปินเอเชียนยอดนิยม / Favorite Asian Artist',
			'08' => 'มิวสิควีดีโอเพลงเอเชียนยอดนิยม / Favorite Asian Music Video',
			'09' => 'ศิลปิน International ยอดนิยม / Favorite International Artist',
			'10' => 'มิวสิควีดีโอเพลง International ยอดนิยม / Favorite International Music Video'
		);		
		
		
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);
	}	
	
	public function ajax_vote()
	{	
		$this->award_model->ajax_vote();
	}
	
	/*Ment*/
	public function ment()
	{
		//Load Nova Slider
		$this->data['js'][] = "jquery.nivo.slider.pack.js";
		$this->data['css'][] = "nivo-slider.css";
		$this->data['css'][] = "themes/default/default.css";
		
		$this->data['dataResult'] = $this->DB_AWARD->select('*,MAX(likes) as likes')->group_by('user_id')->order_by('likes DESC')->get_where('award_comment',array('is_active' => '1'),26)->result();
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	/*Artist*/
	public function artist($cat,$at)
	{
		//Load Nova Slider
		$this->data['js'][] = "jquery.nivo.slider.pack.js";
		$this->data['css'][] = "nivo-slider.css";
		$this->data['css'][] = "themes/default/default.css";
			
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;	
	
		$this->data['folder_path'] =  $this->data['asset_award_upload_path']."artist/".$cat."/".$at;
		$this->data['fb_image'] =  $this->data['asset_award_upload_path']."artist/".$cat."/".$at."/artist_left_panel.jpg";
		$time_limit = time()-(60*60); //last 1 hours 
		$this->data['is_vote'] = $this->DB_AWARD->from('award_vote')->where("user_id = '".$this->session->userdata('fb_id')."' AND cat='".$cat."' AND unix_timestamp(fb_time) > '".$time_limit."'")->count_all_results();
		$this->data['dataXML'] = simplexml_load_file($this->upload_folder.''.$this->data['folder_path']."/data.xml");
		$this->data['dataCategory'] = array(
			'01' => 'ศิลปินชายยอดนิยม / Favorite Male Artist',
			'02' => 'ศิลปินหญิงยอดนิยม / Favorite Female Artist',
			'03' => 'ศิลปินหน้าใหม่ยอดนิยม / Favorite New Artist',
			'04' => 'ศิลปิน Teen Pop ยอดนิยม / Favorite Teen Pop Artist',
			'05' => 'ศิลปินคู่หรือกลุ่มยอดนิยม / Favorite Duo / Group Artist',
			'06' => 'มิวสิควีดีโอเพลงไทยยอดนิยม / Favorite Thai Music Video',
			'07' => 'ศิลปินเอเชียนยอดนิยม / Favorite Asian Artist',
			'08' => 'มิวสิควีดีโอเพลงเอเชียนยอดนิยม / Favorite Asian Music Video',
			'09' => 'ศิลปิน International ยอดนิยม / Favorite International Artist',
			'10' => 'มิวสิควีดีโอเพลง International ยอดนิยม / Favorite International Music Video'
		);
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	/*Vdo*/
	public function vdo()
	{
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;
		
		//Intro MP4 SetUp
		$this->data['dataIntro'] = array(
			array('01','3'),
			array('05','2'),
			array('03','3'),
			array('03','6'),
			array('05','1'),
			array('06','5'),
			array('05','4'),
			array('02','2'),
			array('02','6'),
			array('06','3'),
			array('01','1'),
			array('01','2'),
			array('01','4'),
			array('01','5'),
			array('01','6'),
			array('03','5'),
			array('04','2'),
			array('05','3'),
			array('05','5'),
			array('02','1'),
			array('02','3'),
			array('02','4'),
			array('03','1'),
			array('03','2'),
			array('03','4'),
			array('04','1'),
			array('04','4'),
			array('04','5'),
			array('05','6'),
			array('06','2'),
			array('06','6')
		);
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}	
	
	/*Picture*/
	public function picture()
	{
		//Load Nova Slider
		$this->data['js'][] = "jquery.nivo.slider.pack.js";
		$this->data['css'][] = "nivo-slider.css";
		$this->data['css'][] = "themes/default/default.css";
		
		/*Load Colorbox*/
   		$this->data['js'][]    = "jquery.colorbox-min.js";
    	$this->data['css'][]   = "colorbox.css";
		
		$this->data['dataGallery01'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2011-1',1);	
		$this->data['folderGallery01'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2011-1";
		$this->data['dataGallery02'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2011-2',1);	
		$this->data['folderGallery02'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2011-2";
		$this->data['dataGallery03'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2011-3',1);	
		$this->data['folderGallery03'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2011-3";
		$this->data['dataGallery04'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2play Awards 2013 Celebrity Host',1);	
		$this->data['folderGallery04'] =  $this->data['asset_award_upload_path']."gallery/You2play Awards 2013 Celebrity Host";
		$this->data['dataGallery05'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/MonoChrome Hearts feat. Shintaro Mizuno',1);	
		$this->data['folderGallery05'] =  $this->data['asset_award_upload_path']."gallery/MonoChrome Hearts feat. Shintaro Mizuno";
		$this->data['dataGallery06'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2013-1',1);	
		$this->data['folderGallery06'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2013-1";
		$this->data['dataGallery07'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2013-2',1);	
		$this->data['folderGallery07'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2013-2";
		$this->data['dataGallery08'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2013-3',1);	
		$this->data['folderGallery08'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2013-3";			
		$this->data['dataGallery09'] = directory_map($this->upload_folder.$this->data['asset_award_upload_path'].'gallery/You2PlayAwards 2013-4',1);	
		$this->data['folderGallery09'] =  $this->data['asset_award_upload_path']."gallery/You2PlayAwards 2013-4";
		//$this->data['dataXML05'] = simplexml_load_file($this->upload_folder.''.$this->data['folderGallery05']."/data.xml");
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);				
	}
	
	/*News*/
	public function news()
	{
		//Load Nova Slider
		$this->data['js'][] = "jquery.nivo.slider.pack.js";
		$this->data['css'][] = "nivo-slider.css";
		$this->data['css'][] = "themes/default/default.css";
		
		/*Load Colorbox*/
   		$this->data['js'][]    = "jquery.colorbox-min.js";
    	$this->data['css'][]   = "colorbox.css";		
	
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);				
	}	
	
	/*About*/
	public function about()
	{
		//Load Media Player
		if($this->agent->is_mobile()):
			$this->data['js'][] = "media/player.js";
		else:
			$this->data['js'][] = "media/jwplayerx.js";
		endif;
			
		$this->data['content'] = preg_replace("/_/","/",$this->router->class)."/".$this->router->method;
		$this->load->view("templates/".$this->folder_templates."templates", $this->data);		
	}
	
	/*Mail*/
	public function mail_to_admin()
	{		
		//Get Contact
		$dataContact = $this->db->get('contact_us',1)->row();
		$dataResult->reciever_name = 'PMD+ CO.,Ltd';
		$dataResult->receiver_email = 'vorawatc@pmdplus.com';
		$dataResult->receiver_subject = 'Onisueka';
		$dataResult->reciever_message = 'ทดสอบ';
		$dataResult->receiver_email = $contact_email;
		$dataResult->sender_name = 'Develop You2play';

		//Send Email
		sendEmail($dataResult);	
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */